package com.xinyu.shopping_common.exception;


import cn.dev33.satoken.exception.NotPermissionException;
import com.xinyu.shopping_common.exception.BusException;
import com.xinyu.shopping_common.result.BaseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 项目统一异常处理类
 */

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 业务异常处理方法
     * @param e
     * @return
     */
    @ExceptionHandler(BusException.class)
    public BaseResult busExceptionHandler(BusException e){
        String msg = e.getMsg();
        Integer code = e.getCode();
        return BaseResult.error(code,msg);
    }

    /**
     * 没有权限的异常全局处理
     * @param e
     * @return
     */
    @ExceptionHandler(NotPermissionException.class)
    public BaseResult noPermissionExceptionHandler(NotPermissionException e){
        return BaseResult.error(e.getCode(),e.getMessage());
    }


}
